import { http } from '@/utils/request'
import type { SysDeptDetailsType, SysDeptListType, SysDeptWriteParamsType } from './model'

/**
 * 获取部门树
 * @returns SysDeptListType[]
 */
export const getDeptTreeAPI = () => {
  return http.request<SysDeptListType[]>('get', '/sys_dept')
}

/**
 * 获取部门详情
 * @param id 部门id
 * @returns SysDeptDetailsType
 */
export const getDeptDetailsAPI = (id: number) => {
  return http.request<SysDeptDetailsType>('get', `/sys_dept/${id}`)
}

/**
 * 新增部门
 * @param params SysDeptWriteParamsType
 * @returns boolean
 */
export const addDeptAPI = (params: SysDeptWriteParamsType) => {
  return http.request<boolean>('post', '/sys_dept', { data: params })
}

/**
 * 修改部门
 * @param id 部门ID
 * @param params SysDeptWriteParamsType
 * @returns boolean
 */
export const updateDeptAPI = (id: number, params: SysDeptWriteParamsType) => {
  return http.request<boolean>('put', `/sys_dept/${id}`, { data: params })
}

/**
 * 删除部门
 * @param id 部门ID
 * @returns boolean
 */
export const deleteDeptAPI = (id: number) => {
  return http.request<boolean>('delete', `/sys_dept/${id}`)
}
